<template>
  <div class="bgc-default">
    <div class="top-nav">
      <!-- <div class="nav-item" :class="{'nav-active': active === '1F'}" @click="go(0)">基本信息</div>
      <div class="nav-item" :class="{'nav-active': active === '2F'}" @click="go(1)">供应链/库存</div>
      <div class="nav-item" :class="{'nav-active': active === '3F'}" @click="go(2)">价格设置</div>
      <div class="nav-item" :class="{'nav-active': active === '4F'}" @click="go(3)">参数设置</div>
      <div class="nav-item" :class="{'nav-active': active === '5F'}" @click="go(4)">商品详情</div>
      <div class="nav-item" :class="{'nav-active': active === '6F'}" @click="go(5)">其他设置</div> -->
      <template v-for="(item, index) of topNavBar">
        <div :key="index" class="nav-item" :class="{'nav-active' : topNavBaroIndex === index}" @click="goTarget('#' + item.target, index)">{{item.name}}</div>
      </template>
    </div>
    <div class="circle-x-tab pad-l-20 pad-r-20 mar-t-20">
      <!-- 基本信息 -->
      <goods-info id="base-info" class="scroll-item" :dict="dict" ref="goodsInfo" :fromListPage="fromListPage" ></goods-info>
      <!-- 销量设置 -->
      <goods-supplier id="in-stock" @emitGoodsData="emitGoodsData" :goodsId="goodsId" class="scroll-item" :dict="dict" :fromListPage="fromListPage" ref="goodsSupplier" v-if="getVersionType() == 1 || getVersionType() == 4"></goods-supplier>
      <!-- 价格设置 -->
      <template v-if="goodsSource == 0 || goodsSource == 1">
        <goods-price id="price-set" class="scroll-item" :dict="dict" ref="goodsPrice" :fromListPage="fromListPage" :goodsId="goodsId"></goods-price>
      </template>
      <!-- 套餐商品 -->
      <goods-combo id="goods-combo" class="scroll-item" :dict="dict" ref="goodsCombo" :fromListPage="fromListPage" :goodsId="goodsId"></goods-combo>
      <!-- 参数设置 -->
      <goods-parameter id="params-set" class="scroll-item" ref="goodsParameter" :fromListPage="fromListPage"></goods-parameter>
      <!-- 商品详情 -->
      <goods-detail id="goods-detail" class="scroll-item mar-r-30" ref="goodsDetail" :fromListPage="fromListPage"></goods-detail>
      <!-- 其他设置 -->
      <goods-other id="other-set" class="scroll-item" :dict="dict" :fromListPage="fromListPage" ref="goodsOther"></goods-other>
    </div>
    <div class="bottom-bar">
      <el-button @click="$router.go(-1)">返回</el-button>
      <el-button class="mar-l-30" type="primary" @click="saveGoodsInfo">保存</el-button>
    </div>
  </div>
</template>


<script>
  import elDragDialog from '@/directive/el-dragDialog' // base on element-ui
  import goodsInfo from './components/goods-info'
  import goodsPrice from './components/goods-price'
  import goodsOther from './components/goods-other'
  import goodsParameter from './components/goods-parameter'
  import goodsDetail from './components/goods-detail'
  import goodsTemplate from './components/goods-template'
  import goodsSupplier from './components/goods-supplier'
  import goodsCombo from './components/goods-combo'
  import { getDictByGroupName } from '@/api/common/common'
  import { saveGoods, getGoodsDetail } from '@/api/goods/goods'
  import { addLiveGoods } from '@/api/goods/liveGoods'

  export default {
    components: { goodsInfo, goodsPrice, goodsOther, goodsParameter, goodsDetail, goodsTemplate, goodsSupplier, goodsCombo },
    directives: {
      // 拖动窗口
      elDragDialog
    },
    data() {
      return {
        tabDisabled: true,
        enterpriseId: this.getEnterpriseId(),
        dict: {},
        goodsId: '',
        currentPage: '1',
        templateId: null,
        anchorTemplateId: null,
        listLoading: false,
        fromListPage: 30,
        goodsSource: '0',
        active: '1F',
        scroll: 0,
        divisions: [],
        // 直播库商品
        liveGoods: {},
        topNavBar: [
          { name: '基本信息', target: 'base-info' },
          { name: '销量设置', target: 'in-stock' },
          { name: '价格设置', target: 'price-set' },
          { name: '套餐商品', target: 'goods-combo' },
          { name: '保障/参数设置', target: 'params-set' },
          { name: '商品详情', target: 'goods-detail' },
          { name: '其他设置', target: 'other-set' }
        ],
        topNavBaroIndex: 0
      }
    },
    // 初始化页面
    created() {
      const queryParams = this.getCurrentPage().query
      this.goodsId = !queryParams.goodsId ? '' : queryParams.goodsId
      this.fromListPage = !queryParams.fromListPage ? 30 : queryParams.fromListPage * 1
      this.goodsSource = !queryParams.goodsSource ? '0' : queryParams.goodsSource.toString()
      const currentPage = queryParams.currentPage
      if (currentPage) {
        this.currentPage = currentPage
      }
    },
    beforeDestroy() {
      window.removeEventListener('mousewheel', this.getDomTop)
    },
    mounted() {
      // window.addEventListener('scroll', this.pageScroll)
      // this.divisions = document.getElementsByClassName('scroll-item')
      // if (this.goodsId) {
      //   this.initGoodsInfo()
      // } else {
      //   this.$refs.goodsDetail.detailsBoolean = true
      // }
      // if (this.goodsSource !== 0 && this.goodsSource !== 1) {
      //   this.topNavBar.splice(2, 1)
      // }
      this.$nextTick(function() {
        const queryParams = this.getCurrentPage().query
        if (queryParams.active) {
          this.goTarget(`#${this.topNavBar[queryParams.active]['target']}`, queryParams.active)
        }
        for (let i = 0; i < this.topNavBar.length; i++) {
          const dom = document.getElementById(`${this.topNavBar[i]['target']}`)
          this.$set(this.topNavBar[i], 'top', dom.offsetTop)
          this.$set(this.topNavBar[i], 'h', dom.clientHeight)
        }
      })
      window.addEventListener('mousewheel', this.getDomTop)
      this.initDict()
      // 监听
      this.busMonitor()
    },
    methods: {
      getDomTop() {
        const that = this
        const scroll = document.documentElement.scrollTop || document.body.scrollTop
        const windowHeight = document.documentElement.clientHeight || document.body.clientHeight
        const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight
        for (let i = 0; i < that.topNavBar.length; i++) {
          const dom_id = `${that.topNavBar[i]['target']}`.trim()
          const dom_top = document.getElementById(dom_id).getBoundingClientRect().top
          if (dom_top < 250 && dom_top > 0) {
            that.topNavBaroIndex = i
          }
          if (scroll + windowHeight === scrollHeight) {
            that.topNavBaroIndex = that.topNavBar.length - 1
          }
        }
      },
      goTarget(id, index) {
        document.querySelector(id).scrollIntoView({
          behavior: 'smooth',
          block: 'center'
        })
        this.topNavBaroIndex = index
      },
      emitGoodsData() {
        if (this.goodsId) {
          this.initGoodsInfo()
        } else {
          this.$refs.goodsDetail.detailsBoolean = true
        }
      },
      go(val) {
        const offsetTop = this.divisions[val].offsetTop
        window.scrollTo(0, offsetTop - 100)
      },
      pageScroll() {
        this.scroll = document.documentElement.scrollTop || document.body.scrollTop
        for (var i = this.divisions.length - 1; i >= 0; i--) {
          if (this.scroll >= this.divisions[i].offsetTop - 80) {
            this.active = `${i + 1}F`
            break
          }
        }
      },
      busMonitor() {
        // 文本表单值设置
        const that = this
        this.$bus.$on('ComponentTemplate.templateId.content', function(data) {
          that.templateId = data
          that.saveData()
        })
        this.$bus.$on('ComponentTemplate.bindTemplateId', function(data) {
          if (data.componentType === 'componentAnchorDetail') {
            // Cannot read property 'componentType' of null 异常 先做undefined校验
            that.anchorTemplateId = data.templateId
          } else {
            that.templateId = data.templateId
          }
          if (data.needSaveGoods) {
            that.saveData()
          }
        })
      },
      initDict() {
        getDictByGroupName('ProjectGoodsDTO').then(response => {
          this.dict = response.data
        })
      },
      initGoodsInfo() {
        var data = {
          goodsId: this.goodsId
        }
        getGoodsDetail(data).then((response) => {
          this.$bus.$emit('goods.edit.data', response.data)
        })
      },
      saveGoodsInfo() {
        // 校验
        let checkRet = true
        // 基础信息校验
        checkRet = this.$refs.goodsInfo.checkForm()
        if (!checkRet) {
          return
        }
        // 价格组件校验
        checkRet = this.$refs.goodsPrice.checkForm()
        if (!checkRet) {
          return
        }
        // 其他组件校验
        checkRet = this.$refs.goodsOther.checkForm()
        if (!checkRet) {
          return
        }
        // 套餐组件校验
        checkRet = this.$refs.goodsCombo.checkForm()
        if (!checkRet) {
          return
        }
        if (this.getVersionType() === '1' || this.getVersionType() === '4') {
          // 销量组件校验
          checkRet = this.$refs.goodsSupplier.checkForm()
          if (!checkRet) {
            return
          }
        }
        // 保存模板
        this.$refs.goodsDetail.saveTemplate()
      },
      // 商品加入直播库
      addLiveGoods() {
        addLiveGoods(this.liveGoods).then(response => {
          if (response.isError) return
        })
      },
      saveData() {
        // 排序
        const sortNo = this.$refs.goodsInfo.form.sortNo
        const title = this.$refs.goodsInfo.form.title
        const goodsCode = this.$refs.goodsInfo.form.goodsCode
        const goodsBarCode = this.$refs.goodsInfo.form.goodsBarCode
        const externalCode = this.$refs.goodsInfo.form.externalCode
        const posterTitle = this.$refs.goodsInfo.form.posterTitle
        const posterRecommend = this.$refs.goodsInfo.form.posterRecommend
        const sellPoint = this.$refs.goodsInfo.form.sellPoint
        const shareCopy = this.$refs.goodsInfo.form.shareCopy
        const unit = this.$refs.goodsInfo.form.unit
        const brandId = this.$refs.goodsInfo.form.brandId
        const tiktokAuthority = this.$refs.goodsInfo.form.tiktokAuthority
        const quickAuthority = this.$refs.goodsInfo.form.quickAuthority
        const pinDuoDuoAuthority = this.$refs.goodsInfo.form.pinDuoDuoAuthority
        const taobaoAuthority = this.$refs.goodsInfo.form.taobaoAuthority
        // 商品类型 30: 零售商品 31: 批发商品 32: 零售+批发商品
        const goodsType = this.goodsId ? this.$refs.goodsInfo.form.goodsType : this.fromListPage
        // 图片集合
        const goodsImages = this.$refs.goodsInfo.form.goodsImages
        // 商品分类Id
        const goodscategoryIds = this.$refs.goodsInfo.form.goodscategoryIds
        const wholesaleGoodscategoryIds = this.$refs.goodsInfo.form.wholesaleGoodscategoryIds
        const labelTypes = this.$refs.goodsInfo.form.labelTypes
        // 主播选品字段
        const selectionGoodsType = this.$refs.goodsInfo.form.selectionGoodsType
        // 加入云店小程序
        const storeAppGoodsType = this.$refs.goodsInfo.form.storeAppGoodsType
        const anchorPlatformShopType = this.$refs.goodsInfo.form.anchorPlatformShopType
        // 若开启加入选品库后，全不勾选则保存时提示“至少开启一个商品库”平台。
        // if ((selectionGoodsType === 1 || selectionGoodsType === '1') && anchorPlatformShopType === '0' && tiktokAuthority === '0' && quickAuthority === '0' && pinDuoDuoAuthority === '0' && taobaoAuthority === '0') {
        //   return this.$message({ type: 'error', message: '至少开启一个商品库' })
        // }
        const tiktokGoodsUrl = this.$refs.goodsInfo.form.tiktokGoodsUrl
        const quickGoodsUrl = this.$refs.goodsInfo.form.quickGoodsUrl
        const taobaoGoodsUrl = this.$refs.goodsInfo.form.taobaoGoodsUrl
        const pinDuoDuoGoodsUrl = this.$refs.goodsInfo.form.pinDuoDuoGoodsUrl
        const oneCategoryId = goodscategoryIds[0]
        const twoCategoryId = goodscategoryIds[1]
        const threeCategoryId = goodscategoryIds[2]
        const wholesaleOneCategoryId = wholesaleGoodscategoryIds[0]
        const wholesaleTwoCategoryId = wholesaleGoodscategoryIds[1]
        const wholesaleThreeCategoryId = wholesaleGoodscategoryIds[2]

        const skuFlag = this.$refs.goodsPrice.form.skuFlag
        const sellPrice = this.$refs.goodsPrice.form.sellPrice
        const wholesalePrice = this.$refs.goodsPrice.form.wholesalePrice
        const wholesaleNum = this.$refs.goodsPrice.form.wholesaleNum
        const supplyPrice = this.$refs.goodsPrice.form.supplyPrice
        const wholesalePostFee = this.$refs.goodsPrice.form.wholesalePostFee
        const wholesalePostFeeType = this.$refs.goodsPrice.form.wholesalePostFeeType
        const wholesaleDeliveryTemplateId = this.$refs.goodsPrice.form.wholesaleDeliveryTemplateId
        const gradeList = this.$refs.goodsPrice.form.gradeList
        const memberGradeAuth = this.$refs.goodsPrice.form.memberGradeAuth

        const stock = this.$refs.goodsSupplier.form.stock
        // 主播选品字段
        const virtualPutawayNum = this.$refs.goodsSupplier.form.virtualPutawayNum
        const specimenLimitNum = this.$refs.goodsSupplier.form.specimenLimitNum

        const stockWarn = this.$refs.goodsPrice.form.stockWarn
        const ladderAuth = this.$refs.goodsPrice.form.ladderAuth
        const postFee = this.$refs.goodsPrice.form.postFee
        const postFeeType = this.$refs.goodsPrice.form.postFeeType
        const deliveryTemplateId = this.$refs.goodsPrice.form.deliveryTemplateId
        // 供应价含税和进项税税目
        const supplierTaxFlag = this.$refs.goodsPrice.form.supplierTaxFlag
        const taxItemsId = this.$refs.goodsPrice.form.taxItemsId
        // 主播选品字段
        const anchorPaymentsPrice = this.$refs.goodsPrice.form.anchorPaymentsPrice
        // 分销价
        const distributePrice = this.$refs.goodsPrice.form.distributePrice
        const specimenPrice = this.$refs.goodsPrice.form.specimenPrice

        const weight = this.$refs.goodsOther.form.weight
        const size = this.$refs.goodsOther.form.size
        const prov = this.$refs.goodsOther.form.prov
        const city = this.$refs.goodsOther.form.city
        const goodsStatus = this.$refs.goodsOther.form.goodsStatus
        const wholesaleGoodsStatus = this.$refs.goodsOther.form.wholesaleGoodsStatus
        let supplierId
        let supplierPostFee
        if (this.getVersionType() === '1' || this.getVersionType() === '4') {
          supplierId = this.$refs.goodsSupplier.form.supplierId ? this.$refs.goodsSupplier.form.supplierId : ''
          supplierPostFee = this.$refs.goodsSupplier.form.supplierPostFee ? this.$refs.goodsSupplier.form.supplierPostFee : ''
        }
        if (this.getVersionType() === '5') {
          supplierId = this.$refs.goodsOther.form.supplierId ? this.$refs.goodsOther.form.supplierId : ''
        }
        const goodsParameters = this.$refs.goodsParameter.form.goodsParameters
        // 保障
        const goodsSafeguards = this.$refs.goodsParameter.form.goodsSafeguards
        const enterpriseId = this.enterpriseId
        const templateId = this.templateId
        const anchorTemplateId = this.anchorTemplateId

        const ladderPriceList = this.$refs.goodsPrice.form.ladderPriceList
        const distributeType = this.$refs.goodsPrice.form.distributeType
        const distributeRatio = this.$refs.goodsPrice.form.distributeRatio
        const distributeFee = this.$refs.goodsPrice.form.distributeFee
        const shareMemberRatio = this.$refs.goodsPrice.form.shareMemberRatio
        const shareMemberFee = this.$refs.goodsPrice.form.shareMemberFee
        const levelOnePartnerRatio = !this.$refs.goodsPrice.form.levelOnePartnerRatio ? 0 : this.$refs.goodsPrice.form.levelOnePartnerRatio
        const levelOnePartnerFee = !this.$refs.goodsPrice.form.levelOnePartnerFee ? 0 : this.$refs.goodsPrice.form.levelOnePartnerFee
        const levelTwoPartnerRatio = !this.$refs.goodsPrice.form.levelTwoPartnerRatio ? 0 : this.$refs.goodsPrice.form.levelTwoPartnerRatio
        const levelTwoPartnerFee = !this.$refs.goodsPrice.form.levelTwoPartnerFee ? 0 : this.$refs.goodsPrice.form.levelTwoPartnerFee
        const recruiterRatio = !this.$refs.goodsPrice.form.recruiterRatio ? 0 : this.$refs.goodsPrice.form.recruiterRatio
        const recruiterFee = !this.$refs.goodsPrice.form.recruiterFee ? 0 : this.$refs.goodsPrice.form.recruiterFee
        const anchorRatio = !this.$refs.goodsPrice.form.anchorRatio ? 0 : this.$refs.goodsPrice.form.anchorRatio
        const anchorCommission = !this.$refs.goodsPrice.form.anchorCommission ? 0 : this.$refs.goodsPrice.form.anchorCommission
        // 主播佣金比例设置
        const anchorLevelOnePartnerRatio = !this.$refs.goodsPrice.form.anchorLevelOnePartnerRatio ? 0 : this.$refs.goodsPrice.form.anchorLevelOnePartnerRatio
        const anchorLevelTwoPartnerRatio = !this.$refs.goodsPrice.form.anchorLevelTwoPartnerRatio ? 0 : this.$refs.goodsPrice.form.anchorLevelTwoPartnerRatio
        const anchorRecruiterRatio = !this.$refs.goodsPrice.form.anchorRecruiterRatio ? 0 : this.$refs.goodsPrice.form.anchorRecruiterRatio
        const anchorThirdPlatformRatio = !this.$refs.goodsPrice.form.anchorThirdPlatformRatio ? 0 : this.$refs.goodsPrice.form.anchorThirdPlatformRatio
        const templateType = !this.$refs.goodsPrice.form.templateType ? '1' : this.$refs.goodsPrice.form.templateType
        const scribingPrice = this.$refs.goodsPrice.form.scribingPrice
        const unrealSalesNum = this.$refs.goodsSupplier.form.unrealSalesNum
        const qualityData = this.$refs.goodsCombo.form.qualityData ? this.$refs.goodsCombo.form.qualityData : []
        const shareImageUrl = this.$refs.goodsInfo.form.shareImageUrl
        const picUrl = this.$refs.goodsInfo.form.picUrl
        const posterImageUrl = this.$refs.goodsInfo.form.posterImageUrl
        const subGoodsList = this.$refs.goodsCombo.form.subGoodsList
        const qualityTable = this.$refs.goodsCombo.form.qualityTable
        let table = []
        if (this.goodsSource === '2') {
          table = qualityTable
        } else {
          if (qualityData.length === 1) {
            const skuPropId = qualityData[0].skuPropId
            const skuPropName = qualityData[0].skuPropName
            const singleTable = this.$refs.goodsCombo.form.singleTable
            for (let i = 0; i < singleTable.length; i++) {
              const imageUrl = this.$utils.isExist(singleTable[i].imageUrl) ? singleTable[i].imageUrl : ''
              const price = this.$utils.isExist(singleTable[i].price) ? singleTable[i].price : ''
              const anchorPaymentsPrice = this.$utils.isExist(singleTable[i].anchorPaymentsPrice) ? singleTable[i].anchorPaymentsPrice : ''
              // 分销价
              const distributePrice = this.$utils.isExist(singleTable[i].distributePrice) ? singleTable[i].distributePrice : ''
              const specimenPrice = this.$utils.isExist(singleTable[i].specimenPrice) ? singleTable[i].specimenPrice : ''
              const skuSupplyPrice = this.$utils.isExist(singleTable[i].supplyPrice) ? singleTable[i].supplyPrice : ''
              const skuScribingPrice = this.$utils.isExist(singleTable[i].scribingPrice) ? singleTable[i].scribingPrice : ''
              const skuWholesalePrice = this.$utils.isExist(singleTable[i].wholesalePrice) ? singleTable[i].wholesalePrice : ''
              const skuGoodsBarCode = this.$utils.isExist(singleTable[i].goodsBarCode) ? singleTable[i].goodsBarCode : ''
              const skuExternalCode = this.$utils.isExist(singleTable[i].externalCode) ? singleTable[i].externalCode : ''
              const warnStock = this.$utils.isExist(singleTable[i].warnStock) ? singleTable[i].warnStock : ''
              const stock = this.$utils.isExist(singleTable[i].stock) ? singleTable[i].stock : ''
              const deliveryTemplateId = this.$utils.isExist(singleTable[i].deliveryTemplateId) ? singleTable[i].deliveryTemplateId : ''
              const wholesaleDeliveryTemplateId = this.$utils.isExist(singleTable[i].wholesaleDeliveryTemplateId) ? singleTable[i].wholesaleDeliveryTemplateId : ''
              const subGoodsList = this.$utils.isExist(singleTable[i].subGoodsList) ? singleTable[i].subGoodsList : ''

              const skuPropValueId = singleTable[i].skuPropValueId
              const skuPropValue = singleTable[i].skuPropValue

              const projectGoodsSkuDTO = {}
              projectGoodsSkuDTO.skuId = singleTable[i].skuId || ''
              projectGoodsSkuDTO.imageUrl = imageUrl
              projectGoodsSkuDTO.price = price
              projectGoodsSkuDTO.anchorPaymentsPrice = anchorPaymentsPrice
              // 分销价
              projectGoodsSkuDTO.distributePrice = distributePrice
              projectGoodsSkuDTO.specimenPrice = specimenPrice
              projectGoodsSkuDTO.scribingPrice = skuScribingPrice
              projectGoodsSkuDTO.wholesalePrice = skuWholesalePrice
              projectGoodsSkuDTO.goodsBarCode = skuGoodsBarCode
              projectGoodsSkuDTO.externalCode = skuExternalCode
              projectGoodsSkuDTO.supplyPrice = skuSupplyPrice
              projectGoodsSkuDTO.warnStock = warnStock
              projectGoodsSkuDTO.stock = stock
              projectGoodsSkuDTO.deliveryTemplateId = deliveryTemplateId
              projectGoodsSkuDTO.wholesaleDeliveryTemplateId = wholesaleDeliveryTemplateId
              const skuPropValueList = []
              const propValue = {
                skuPropId: skuPropId,
                skuPropName: skuPropName,
                skuPropValueId: skuPropValueId,
                skuPropValue: skuPropValue
              }
              skuPropValueList.push(propValue)
              projectGoodsSkuDTO.skuPropValueList = skuPropValueList
              projectGoodsSkuDTO.subGoodsList = subGoodsList
              table.push(projectGoodsSkuDTO)
            }
          } else {
            for (let i = 0; i < qualityTable.length; i++) {
              const item = qualityTable[i]
              const projectGoodsSkuDTO = {}
              projectGoodsSkuDTO.skuId = item.skuId || ''
              projectGoodsSkuDTO.imageUrl = this.$utils.isExist(item['imageUrl']) ? item['imageUrl'] : ''
              projectGoodsSkuDTO.price = this.$utils.isExist(item['price']) ? item['price'] : ''
              projectGoodsSkuDTO.anchorPaymentsPrice = this.$utils.isExist(item['anchorPaymentsPrice']) ? item['anchorPaymentsPrice'] : ''
              // 分销价
              projectGoodsSkuDTO.distributePrice = this.$utils.isExist(item['distributePrice']) ? item['distributePrice'] : ''
              projectGoodsSkuDTO.specimenPrice = this.$utils.isExist(item['specimenPrice']) ? item['specimenPrice'] : ''
              projectGoodsSkuDTO.scribingPrice = this.$utils.isExist(item['scribingPrice']) ? item['scribingPrice'] : ''
              projectGoodsSkuDTO.wholesalePrice = this.$utils.isExist(item['wholesalePrice']) ? item['wholesalePrice'] : ''
              projectGoodsSkuDTO.goodsBarCode = this.$utils.isExist(item['goodsBarCode']) ? item['goodsBarCode'] : ''
              projectGoodsSkuDTO.externalCode = this.$utils.isExist(item['externalCode']) ? item['externalCode'] : ''
              projectGoodsSkuDTO.supplyPrice = this.$utils.isExist(item['supplyPrice']) ? item['supplyPrice'] : ''
              projectGoodsSkuDTO.stock = this.$utils.isExist(item['stock']) ? item['stock'] : ''
              projectGoodsSkuDTO.warnStock = this.$utils.isExist(item['warnStock']) ? item['warnStock'] : ''
              projectGoodsSkuDTO.deliveryTemplateId = this.$utils.isExist(item['deliveryTemplateId']) ? item['deliveryTemplateId'] : ''
              projectGoodsSkuDTO.wholesaleDeliveryTemplateId = this.$utils.isExist(item['wholesaleDeliveryTemplateId']) ? item['wholesaleDeliveryTemplateId'] : ''
              const skuPropValueList = []
              for (const key in item) {
                if (this.$utils.isExist(item[key].skuPropId)) {
                  const skuPropId = item[key].skuPropId
                  const skuPropName = item[key].skuPropName
                  const skuPropValue = item[key].skuPropValue
                  const skuPropValueId = item[key].skuPropValueId
                  const projectGoodsSkuPropValueDTO = {
                    skuPropId: skuPropId,
                    skuPropName: skuPropName,
                    skuPropValue: skuPropValue,
                    skuPropValueId: skuPropValueId
                  }
                  skuPropValueList.push(projectGoodsSkuPropValueDTO)
                }
              }
              projectGoodsSkuDTO.skuPropValueList = skuPropValueList
              projectGoodsSkuDTO.subGoodsList = item['subGoodsList']
              table.push(projectGoodsSkuDTO)
            }
          }
        }

        const data = {
          comboType: 2,
          enterpriseId: enterpriseId,
          goodsSource: this.goodsSource,
          sortNo: sortNo,
          title: title,
          posterTitle: posterTitle,
          posterRecommend: posterRecommend,
          sellPoint: sellPoint,
          shareCopy: shareCopy,
          unit: unit,
          brandId: brandId,
          storeAppGoodsType: storeAppGoodsType,
          // 选品库开关控制的平台选项
          selectionGoodsType: selectionGoodsType,
          anchorPlatformShopType: anchorPlatformShopType,
          quickAuthority: quickAuthority,
          tiktokAuthority: tiktokAuthority,
          pinDuoDuoAuthority: pinDuoDuoAuthority,
          taobaoAuthority: taobaoAuthority,
          tiktokGoodsUrl: tiktokGoodsUrl,
          quickGoodsUrl: quickGoodsUrl,
          pinDuoDuoGoodsUrl: pinDuoDuoGoodsUrl,
          taobaoGoodsUrl: taobaoGoodsUrl,
          goodsType: goodsType,
          goodsImages: goodsImages,
          oneCategoryId: oneCategoryId,
          twoCategoryId: twoCategoryId,
          threeCategoryId: threeCategoryId,
          wholesaleOneCategoryId: wholesaleOneCategoryId,
          wholesaleTwoCategoryId: wholesaleTwoCategoryId,
          wholesaleThreeCategoryId: wholesaleThreeCategoryId,
          skuFlag: skuFlag,
          sellPrice: sellPrice,
          supplyPrice: supplyPrice,
          wholesalePrice: wholesalePrice,
          // 主播结算价
          anchorPaymentsPrice: anchorPaymentsPrice,
          // 分销价
          distributePrice: distributePrice,
          specimenPrice: specimenPrice,
          goodsCode: goodsCode,
          goodsBarCode: goodsBarCode,
          externalCode: externalCode,
          wholesaleNum: wholesaleNum,
          stock: stock,
          stockWarn: stockWarn,
          ladderAuth: ladderAuth,
          postFeeType: postFeeType,
          postFee: postFee,
          deliveryTemplateId: deliveryTemplateId,
          wholesalePostFeeType: wholesalePostFeeType,
          wholesalePostFee: wholesalePostFee,
          wholesaleDeliveryTemplateId: wholesaleDeliveryTemplateId,
          gradeList: gradeList,
          memberGradeAuth: memberGradeAuth,
          wholesaleGoodsStatus: wholesaleGoodsStatus,
          goodsStatus: goodsStatus,
          supplierId: supplierId,
          supplierPostFee: supplierPostFee,
          goodsParameters: goodsParameters,
          goodsSafeguards: goodsSafeguards,
          labelTypes: labelTypes,
          goodsId: this.goodsId,
          detailTemplateId: templateId,
          anchorTemplateId: anchorTemplateId,
          distributeType: distributeType,
          ladderPriceList: ladderPriceList,
          distributeRatio: distributeRatio,
          distributeFee: distributeFee,
          shareMemberRatio: shareMemberRatio,
          shareMemberFee: shareMemberFee,
          levelOnePartnerRatio: levelOnePartnerRatio,
          levelOnePartnerFee: levelOnePartnerFee,
          levelTwoPartnerRatio: levelTwoPartnerRatio,
          levelTwoPartnerFee: levelTwoPartnerFee,
          recruiterRatio: recruiterRatio,
          recruiterFee: recruiterFee,
          anchorRatio: anchorRatio,
          anchorCommission: anchorCommission,
          // 主播佣金设置相应字段
          anchorLevelOnePartnerRatio: anchorLevelOnePartnerRatio,
          anchorLevelTwoPartnerRatio: anchorLevelTwoPartnerRatio,
          anchorRecruiterRatio: anchorRecruiterRatio,
          anchorThirdPlatformRatio: anchorThirdPlatformRatio,
          templateType: templateType,
          unrealSalesNum: unrealSalesNum,
          // 虚拟上架人数
          virtualPutawayNum: virtualPutawayNum,
          // 样品限购数
          specimenLimitNum: specimenLimitNum,
          scribingPrice: scribingPrice,
          qualityData: qualityData,
          shareImageUrl: shareImageUrl,
          picUrl: picUrl,
          posterImageUrl: posterImageUrl,
          qualityTable: table,
          weight: weight,
          size: size,
          prov: prov,
          city: city,
          supplierTaxFlag: supplierTaxFlag,
          taxItemsId: taxItemsId,
          subGoodsList: subGoodsList
        }
        this.isSubmit = true
        if (!this.isSubmit) {
          return
        }
        this.listLoading = true

        this.loading = this.$loading({
          lock: true,
          text: '保存中',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
        saveGoods(data).then((response) => {
          this.listLoading = false
          this.loading.close()
          if (response.isError) {
            // this.isSubmit = false
            return
          }
          // const goodsId = response.data
          // 加入选品库且开启小程序直播的商品加入到直播商品库
          // if ((data.selectionGoodsType === 1 || data.selectionGoodsType === '1') && data.anchorPlatformShopType === '1' && data.goodsStatus === '1') {
          //   this.liveGoods = {
          //     enterpriseId: this.getEnterpriseId(),
          //     goodsImgUrl: data.goodsImages[0].imageUrl,
          //     priceType: '1',
          //     price: data.sellPrice,
          //     minPrice: '',
          //     maxPrice: '',
          //     originalPrice: data.sellPrice,
          //     nowPrice: data.sellPrice,
          //     auditStatus: '0',
          //     goodsId: goodsId,
          //     title: data.title
          //   }
          //   this.addLiveGoods()
          // }
          // this.$message({
          //   type: 'success',
          //   message: '保存成功!'
          // })
          this.$bus.$off('ComponentTemplate.templateId.content')
          this.$bus.$off('ComponentTemplate.bindTemplateId')
          this.$bus.$off('ComponentTemplate.anchorTemplateId.content')
          this.$router.push({ path: '/goods/combo/index/', query: { currentPage: this.currentPage.toString() }})
        })
      }
    }
  }
</script>

<style lang="less" scoped>
.circle-x-tab{
  padding-bottom: 70px;
  /deep/.el-checkbox__label{
    font-size: 16px;
  }
  /deep/.el-radio__label{
    font-size: 14px;
  }
  /deep/.el-checkbox__inner{
    width: 14px;
    height: 14px;
  }

  /deep/.el-checkbox__inner{
    width: 18px;
    height: 18px;
  }
  /deep/.form-diy .el-form-item{
    background: none;
  }
  /deep/.form-diy .el-form-item.none-mar-b{
    margin-bottom: 0!important;
  }
  /deep/.form-diy .el-color-picker--medium .el-color-picker__trigger{
    width: 100px;
  }
  /deep/.form-diy .el-color-picker__empty, /deep/.form-diy .el-color-picker__icon{
    left: 80%;
  }
  /deep/.form-diy .el-form-item__label{
    font-size: 14px!important;
    font-weight: normal!important;
  }
  /deep/.form-diy .el-upload--picture-card{
    width: 100px;
    height: 100px;
    line-height: 100px;
  }
  /deep/.el-form-item{
    background: white;
  }
  /deep/.el-form-item .el-form-item{
    margin-bottom: 22px;
  }
  /deep/.one-label>.el-form-item__label{
    text-align: center;
    font-size: 16px;
    padding-top: 22px;
    color: #333;
    font-family: "微软雅黑", "Arial", "sans-serif";
  }
  /deep/.one-label>.el-form-item__content{
    padding: 20px 50px 20px 0;
    border-left:#F7F8FA 10px solid;
    .el-form-item__label{
      font-size: 14px;
    }
  }
  /deep/.el-form-item__content{
    font-size: 14px;
    .el-form-item__label{
      font-size: 18px;
      font-weight: normal;
    }
  }
}
.top-nav{
  position: sticky;
  // top: 50px;
  top:0;
  left: 0;
  width: 100%;
  height: 60px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 999;
  box-shadow: 0 2px 6px #eee;
  .nav-item{
    cursor: pointer;
  }
  .nav-active{
    position: relative;
    color: #409eff;
    &::after{
      content: '';
      position: absolute;
      bottom: -20px;
      left: -15px;
      width: calc(100% + 30px);
      height: 2px;
      background-color: #409eff;
    }
  }
}
.bottom-bar{
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  z-index: 999;
  box-shadow: 5px 1px 5px #cccccc;
  .el-button{
    width: 100px;
    height: 40px;
    line-height: 40px;
    padding: 0;
  }
  .el-button+.el-button{
    margin-left: 30px;
  }
}
  .el-form-item__content {
    .el-button {
      padding: 0;
      height: 34px;
      width: 139px;
    }
  }
  .span-bar{
    padding: 0 50px;
  }
  .remove-btn{
    padding: 7px 6px!important;
  }
  .long-input{
    width: 80%;
  }
  .long-input-2{
    width: 55%;
    margin-right: 5%;
  }
  .long-input-3{
    width: 55%;
  }
  .short-input{
    width: 20%;
  }
  .short-input-2{
    width: 25%;
  }
  .default-input{
    width: 50%;
  }
  .tips{
    color: gray;
    font-size: 12px;
    line-height: 1.2;
    padding-top: 5px;
  }
  .picture{
    width: 130px;
    height: 130px;
    display: block;
  }
  .pic-bar{
    position: relative;
    .close-icon{
      position: absolute;
      right: -30px;
      top: -11px;
      width: 31px;
      height: 40px;
      padding: 0 7px;
      cursor: pointer;
    }
    span{
      position: absolute;
      right: 0;
      bottom: 0;
      width: 100%;
      display: block;
      color: #fff;
      text-align: center;
      padding: 3px 0;
      background: rgba(0,0,0,0.5);
      cursor: pointer;
    }
  }
  .pic-add{
    background: #fff;
    border: #d3d3d3 1px dashed;
    border-radius: 5px;
    padding: 0 45px;
  }
  .bottom-btn{
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
  }
</style>
